function stilde = stildefun(sbar,p)

% check for corner solution:
if wagediff(sbar,sbar+p.stol,p) >= 0
    
    stilde = sbar;
    return
    
elseif wagediff(sbar,1-p.stol,p) <= 0
    
    stilde = 1;
    return
    
end

% interior solution:
stilde = fzero(@(stilde) wagediff(sbar,stilde,p),[sbar+p.stol 1-p.stol],p.optionsfzero);

end
    